
#ifndef __H_LIST_H__
#define __H_LIST_H__

#include "linux_def.h"
#include "core.h"

typedef struct list_part_s	list_part_t;

struct list_part_s{
	void	*elts;	//指向实际节点，存放nalloc*size大小
	int	nelts;	//成员个数
	list_part_t	*next;	//下个节点
};

typedef struct{
	list_part_t	*last;	//最后一个元素指针
	list_part_t	part;	//第一个节点
	size_t		size;	//每个元素大小
	int		nalloc;	//总的个数
	pool_t		*pool;
}list_t;

list_t	*list_create(pool_t *pool, int n, size_t size);

static inline int list_init(list_t *list, pool_t *pool, int n, size_t size)
{
	list->part.elts	= (void *)palloc(pool, n * size);
	if (list->part.elts == NULL)
		return -1;

	list->part.nelts	= 0;
	list->part.next		= 0;
	list->last	= &list->part;
	list->size	= size;
	list->nalloc	= n;
	list->pool	= pool;

	return 0;
}

void	*list_push(list_t *list);

#endif
